package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by v on 17-4-11.
 */
@WebFilter(filterName = "FilterLogIn",value = "/testjsp/4.11/logIn.html")
public class FilterLogIn implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request=(HttpServletRequest) servletRequest;
        HttpServletResponse response=(HttpServletResponse) servletResponse;

        //获取该ip所登录的user
        String user=(String) request.getSession().getAttribute(servletRequest.getRemoteAddr());
        if(user!=null){
            filterChain.doFilter(servletRequest,servletResponse);
        }else {
            response.sendRedirect("/testjsp/4.11/skipBack.jsp");
        }
    }
}